#!/bin/bash
#================================================{ Messages }===========================================================
case "$day$month${virus,,}${dow,,}" in
   *covid-19*) ad='Stay at home!'                              ;;&
        *fri*) ad='All work and no play makes Jack a dull boy' ;;&
        3112*) ad="Happiu-piu new $((year+1))"' year!)'        ;;
        1101*) ad='Happy birthday Yura $)'                     ;;
        0202*) ad='It is groundhog day, again !)'              ;;
        2002*) ad='Happy birthday Romka !)'                    ;;
        2302*) ad='Where is my socks and shaving foam!?'       ;;
        2802*) ad='Happy birthday Matvey !)'                   ;;
        0803*) ad='Hold on guyz $)'                            ;;
        1803*) ad='Happy birthday Ivinco !)'                   ;;
        0905*) ad='День победы!'                               ;;
        3006*) ad='Happy birthday Natusya !)'                  ;;
esac
#------------------------{ Ad plane text }------------------------------------------------------------------------------
ad_plane_text () {
    case $type in duel) ad='Try to catch this!' ad_new=;; esac
    CM4= CM5=; case "$day$month" in 0905) CM4=$bylw CM5=$bblk;; esac
    for ((i=0; i<${#ad}; i++)); do ad_new+="$CM5$BLD$red${ad:$i:1} "; done
    new_ad=( ${ad_new//  /⎕ } ) line=( ${new_ad[@]//*/$CM4$blk-} ) width=$((19+${#new_ad[@]}))
};  ad_plane_text

#↑ ↓ ← → ▲ ▼ ▶ ◀ ▷ ◁ △ ▽
sprite_help () {
    x=$[$endx/2-25/2]
    y=$[$endy/2-5]
    XY $[x+19]  $y                                       '▲'
    XY $[x+19] $[y+1]                              "${RED}W$DEF"
    XY  $x     $[y+2] "${BLD}Control with:$DEF  ◀ ${RED}A S D$DEF ▶"
    XY $[x+19] $[y+3]                                    '▼'
    XY  $x     $[y+5] "${BLD}Shoot\select with:$DEF ${YLW}P $BLD$red-=$GRN>$DEF"
}

sprite_lose () {
    x=$[$endx/2-25/2] CM1=$BLD$red
    y=$[$endy/2-5]    CM2=$DIM$RED
    XY $x  $y    "$CM1  ____    _    __  __ _____ $DEF"
    XY $x $[y+1] "$red / ___|  / \  |  \/  | ____|$DEF"
    XY $x $[y+2] "$red| | __  / _ \ | |\/| |  _|  $DEF"
    XY $x $[y+3] "$RED| |_\ \/ ___ \| |  | | |___ $DEF"
    XY $x $[y+4] "$CM2 \____/_/   \_\_|__|_|_____|$DEF"
    XY $x $[y+5] "$CM1  / _ \ \   / / ____|  _ \  $DEF"
    XY $x $[y+6] "$red | | | \ \ / /|  _| | |_) | $DEF"
    XY $x $[y+7] "$RED | |_| |\ V / | |___|  _ <  $DEF"
    XY $x $[y+8] "$CM2  \___/  \_/  |_____|_| \_| $DEF"
}

sprite_win () {
    x=$[$endx/2-25/2] CM1=$BLD$grn
    y=$[$endy/2-5]    CM2=$DIM$GRN
    XY $x  $y  "${CM1}__        ______ _    _    $DEF"
    XY $x $[y+1] "$grn\ \      / /____| |  | |   $DEF"
    XY $x $[y+2] "$grn \ \ /\ / /  _| | |  | |   $DEF"
    XY $x $[y+3] "$GRN  \ V  V /| |___| |__| |__ $DEF"
    XY $x $[y+4] "$CM2 __\_/\_/_|_____|____|____|$DEF"
    XY $x $[y+5] "$CM1|  _ \ / _ \| \ | | ____| |$DEF"
    XY $x $[y+6] "$grn| | | | | | |  \| |  _| | |$DEF"
    XY $x $[y+7] "$GRN| |_| | |_| | |\  | |___|_|$DEF"
    XY $x $[y+8] "$CM2|____/ \___/|_| \_|_____(_)$DEF"
}

sprite_tobe () {
    x=10          CM1=$DIM$WHT CM3=$red
    y=$[$endy-10] CM2=$DIM$red CM4=$BLD$YLW CM5=$ylw
    XY $x $[y+1] $CM1'     __ __ _                                                 '$DEF
    XY $x $[y+2] $CM2'   / /________  ___    ___-  ---___ _    ___   __ _     ___  '$DEF
    XY $x $[y+3] $CM3'  ////_  __/_  / /_____  _____ _ __ / /_(_)_ __ _____ _/ /   '$DEF
    XY $x $[y+4] $RED' ///  / /  \  / _  \_ \ / _/_ \  _ \ __/ /_ \/ / /_ \_  /    '$DEF
    XY $x $[y+5] $YLW'/ /  / /(_) |/ /_) |__// (_(_) |// // / / / /_/ / __// /     '$DEF
    XY $x $[y+6] $CM4'\ \ /_/\___//_.___/__/ \___\__///_/_//_/ /_/__,_|__|_,_|_    '$DEF
    XY $x $[y+7] $CM5' \_\____ ______  __   -----------  __________  ----'"$CM1  ______ __"$DEF
}
#------------------------{ And here the story goes... }-----------------------------------------------------------------
the_story(){
    [[ $type == duel ]] && exit
    color="$DEF$BLD$RED" # main color
    story=(
        "$DEF${RED}Our ${color}research team started to observe the debris of alien mothership."
        "${color}But it's already clear that they are came from $DEF${red}Mars.$DEF${RED}.$DEF$DIM${red}."
        ''
        "${color}The research will be continued but we must act quickly."
        "${color}Lets start our $DEF${red}Mars $DEF${RED}mission $DEF$DIM${red}immediately."
        "${color}One famous $DEF${RED}ornithologist ${color}agree to help us with the transport."
        "${color}Prepare all what is needed for this mission at once."
        "${color}The fait of whole $DEF${RED}mankind ${color}is at $DEF${red}stake!$DEF${RED}.$DEF$DIM${red}."
        "${color}Be brave, it could be a one way ticket."
        ''
        ''
        "${color}Go$DEF${red}od $DEF${RED}lu$DEF$DIM${red}ck!.."
        ''
        ''
        "${color}end of transmission"
        "${color}press any $DEF${red}key $DEF${RED}to $DEF$DIM${red}continue "
    )

    clear
    x=3 y=2
    for line in "${story[@]}"; do
        size=${#line}
        for ((i=1; i<=size; i++)); {
            [[ ${line:$((i-1)):3} =~ \\e\[ ]] && ((i+=6))
            XY $x $y "${line:0:i}"
            sleep $storyspd
        }
        ((y++))
    done
    printf "$DEF"
    read   -srn1
    clear
}
